
package org.apache.commons.el;

import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.el.VariableResolver;
import javax.servlet.jsp.el.ELException;

/**
 *
 * <p>This is the JSTL-specific implementation of VariableResolver.
 * It looks up variable references in the PageContext, and also
 * recognizes references to implicit objects.
 * 
 * @author Nathan Abramson - Art Technology Group
 * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: luehe $
 **/

public class VariableResolverImpl
  implements VariableResolver
{
  //-------------------------------------
  // Member variables
  //-------------------------------------

  private PageContext mCtx;

  //-------------------------------------
  /**
   *
   * 构造函数
   **/
  public VariableResolverImpl (PageContext pCtx)
  {
    mCtx = pCtx;
  }
  
  //-------------------------------------
  /**
   *
   * 在特定上下文中解析变量的值,如果该作用域中没有定义提供的变量名就返回null.
   **/
  public Object resolveVariable (String pName)
    throws ELException
  {
    // 判断隐式对象的类型
    if ("pageContext".equals (pName)) {
      return mCtx;
    }
    else if ("pageScope".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getPageScopeMap ();
    }
    else if ("requestScope".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getRequestScopeMap ();
    }
    else if ("sessionScope".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getSessionScopeMap ();
    }
    else if ("applicationScope".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getApplicationScopeMap ();
    }
    else if ("param".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getParamMap ();
    }
    else if ("paramValues".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getParamsMap ();
    }
    else if ("header".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getHeaderMap ();
    }
    else if ("headerValues".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getHeadersMap ();
    }
    else if ("initParam".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getInitParamMap ();
    }
    else if ("cookie".equals (pName)) {
      return ImplicitObjects.
	getImplicitObjects (mCtx).
	getCookieMap ();
    }

    // Otherwise, just look it up in the page context
    //如果以上操作没有返
    else {
      return mCtx.findAttribute (pName);
    }
  }
					
  //-------------------------------------
}
